package com.light.generator.dao;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 *
 * @ClassName:  GeneratorDao
 * @Description:TODO
 * @date:   2018年11月12日 上午11:40:27
 *
 */
@Component
@Mapper
public interface GeneratorDao {

//	@Select("select a.table_name tableName, a.tablespace_name engine, b.comments tableComment, a.last_analyzed createTime from user_tables a " +
//			"left join user_tab_comments b on a.table_name = b.table_name")
	/**
	 * show
	 * @Title: list   
	 * @Description:
	 * @param: @return
	 * @return: List<Map<String,Object>>      
	 * @throws
	 */
	@Select("select table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables"
			+ " where table_schema = (select database())")
	List<Map<String, Object>> list();

	@Select("select count(*) from information_schema.tables where table_schema = (select database())")
//	@Select("select count(*) from user_tables")
	/**
	 * show
	 * @Title: count   
	 * @param: @param map
	 * @param: @return      
	 * @return: int      
	 * @throws
	 */
	int count(Map<String, Object> map);

	@Select("select table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables \r\n"
			+ "	where table_schema = (select database()) and table_name = #{tableName}")
//	@Select("select a.table_name tableName, b.comments tableComment, a.tablespace_name engine, a.last_analyzed createTime from user_tables a " +
//			"left join user_tab_comments b on a.table_name = b.table_name where a.table_name = #{tableName}")
	/**
	 * show
	 * @Title: get   
	 * @Description: 得到表信息
	 * @param: @param tableName
	 * @param: @return      
	 * @return: Map<String,String>      
	 * @throws
	 */
	Map<String, String> getTableInfo(String tableName);

	@Select("select column_name columnName, data_type dataType, column_comment columnComment, column_key columnKey, extra from information_schema.columns\r\n"
			+ " where table_name = #{tableName} and table_schema = (select database()) order by ordinal_position")
//	@Select("select a.column_name columnname, a.data_type datatype, b.comments columncomment, c.constraint_type columnkey, histogram extra \r\n" +
//			"from user_tab_columns a \r\n" +
//			"    left join user_col_comments b on a.table_name = b.table_name and a.column_name = b.column_name \r\n" +
//			"    left join (select table_name, column_name, 'PRI' constraint_type from user_cons_columns \r\n" +
//			"where constraint_name = ( \r\n" +
//			"        select constraint_name from user_constraints where table_name = 'T_SYS_ROLE' and constraint_type = 'P' \r\n" +
//			"    )) c on a.table_name = c.table_name and a.column_name = c.column_name \r\n" +
//			"where a.table_name = #{tableName}  order by a.column_id")
	/**
	 * show
	 * @Title: listColumns   
	 * @param: @param tableName
	 * @param: @return      
	 * @return: List<Map<String,String>>      
	 * @throws
	 */
	List<Map<String, String>> getTableColums(String tableName);
}
